package com.xh.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.http.HttpSession;

@Configuration
public class MyWebConfig implements WebMvcConfigurer {
    static String path = "";

    /* 用来接收图片的全名称 */
    static public void getHeadPath(HttpSession session) {
        path = (String) session.getAttribute("headPath");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyInterceptors())
                .addPathPatterns("/*", "/blog/blogadmin", "/blog/toNewBlog", "/blog/toIframe")
                .excludePathPatterns("/register", "/toRegister", "/blog/index",
                        "/blog", "/toRegister", "", "/", "/index", "/blog/toLogin", "/login", "/kaptcha", "/queryName", "/toAbout");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置资源访问路径
        registry.addResourceHandler("/abc/**").addResourceLocations("file:" + "C:\\abc\\" + path);
        System.out.println(path);
    }

}
